<?php

namespace common\entities\common;

use common\entities\ConfigEntity;
use Yii;

/**
 * 产品包价格实体
 * Class PackagePriceEntity
 * @package common\entities\common
 */
class MyscrmPackagePriceEntity extends ConfigEntity {

    public static function tableName() {
        return 'myscrm_package_price';
    }


    public function rules() {
        return [
            [['id', 'package_id', 'price', 'unit'], 'required'],
            [['created_by', 'modified_by', 'id', 'package_id'], 'string', 'max' => 36],
            [['unit'], 'string', 'max' => 30],
            [['price'], 'double'],
        ];
    }

    public function attributeLabels() {
        return [
            'id' => 'ID',
            'package_id' => 'Package ID',
            'price' => 'Price',
            'unit' => 'Unit',
            'created_by' => 'Created By',
            'modified_by' => 'Modified By',
            'created_on' => 'Created On',
            'modified_on' => 'Modified By',
        ];
    }

    /**
     * 得到package的price
     * @param $package_id
     * @return int
     */
    public static function getPackagePrice($package_id){
        $price = MyscrmPackagePriceEntity::findOne([
            'package_id' => $package_id
        ]);
        if(!empty($price)){
            return $price['price'];
        }
        return 0;
    }

}
